//引入redis
const redis = require('module/redisSet')
//创建redis客户端
const client = redis.createClient(6379,"127.0.0.1",{});
//连接错误处理
client.on("error", function (error) {
    console.log(error);
});
//redis验证 （如果redis没有开启验证，此配置可以不写）
client.auth("123456");

const query = function(bottle,callback){
    bottle.time = bottle.time || Date.now();
    var bottleId = Math.random().toString(16);
    var type = {male:0,female:1};
    console.log(type[bottle.type]);
    /*client.SELECT选择数据库编号*/
    client.SELECT(type[bottle.type],function(){
        /*client.HMSET 保存哈希键值*/
        client.HMSET(bottleId,bottle,function(err,result){
            if(err){
                return callback({code:0,msg:"过会儿再来试试吧！"});
            }
            callback({code:1,msg:result});
            /*设置过期时间为1天*/
            client.EXPIRE(bottleId,86400);
        });
    });
}

module.exports = query
